<template>
<el-dialog :title="$t('plus.download_qrcode')" v-model="dialogVisible" @close="dialogFormVisible" :close-on-click-modal="false"
    :close-on-press-escape="false">
    <el-form size="small" :model="form">
      <el-form-item :label="$t('plus.download_type')" :label-width="formLabelWidth">
        <el-radio-group v-model="source">
          <el-radio label="wx">{{$t('plus.wechat_mini_program')}}</el-radio>
          <el-radio label="mp">{{$t('plus.wechat_h5')}}</el-radio>
        </el-radio-group>
      </el-form-item>
    </el-form>
    <template #footer>
    <div class="dialog-footer">
      <el-button @click="dialogFormVisible">{{$t('plus.cancel')}}</el-button>
      <el-button type="primary" @click="qrcodeClick">{{$t('plus.confirm')}}</el-button>
    </div>
    </template>
  </el-dialog>
</template>

<script>
import qs from 'qs';
import { getCookie } from '@/utils/base.js';
export default {
  data() {
    return {
      /*左边长度*/
      formLabelWidth: '120px',
      dialogVisible: false,
      source: 'wx'
    };
  },
  props: ['open_qrcode', 'form'],
  created() {
    this.dialogVisible = this.open_qrcode;
  },
  methods: {
    qrcodeClick() {
      let baseUrl = window.location.protocol + '//' + window.location.host;
      let params = {
        id: this.form.giftPackageId,
        source: this.source,
        tokenshop: getCookie('token_shop')
      };
      window.location.href = baseUrl + '/api/shop/plus/package/qrcode?' + qs.stringify(params);
    },
    /*关闭弹窗*/
    dialogFormVisible(e) {
      if (e) {
        this.$emit('closeDialog', {
          type: 'success',
          openDialog: false
        });
      } else {
        this.$emit('closeDialog', {
          type: 'error',
          openDialog: false
        });
      }
    }
  }
};
</script>

